package com.ruoyi.oos.web.controller.duty;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.oos.duty.domain.DutyTeam;
import com.ruoyi.oos.duty.service.IDutyTeamService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 轮值班组信息Controller
 * 
 * @author bulang
 * @date 2020-04-28
 */
@Controller
@RequestMapping("/duty/team")
public class DutyTeamController extends BaseController
{
    private String prefix = "duty/team";

    @Autowired
    private IDutyTeamService dutyTeamService;

    @RequiresPermissions("duty:team:view")
    @GetMapping()
    public String team()
    {
        return prefix + "/team";
    }

        /**
     * 查询轮值班组信息列表
     */
    @RequiresPermissions("duty:team:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DutyTeam dutyTeam)
    {
        startPage();
        List<DutyTeam> list = dutyTeamService.selectDutyTeamList(dutyTeam);
        return getDataTable(list);
    }
    
    /**
     * 导出轮值班组信息列表
     */
    @RequiresPermissions("duty:team:export")
    @Log(title = "轮值班组信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DutyTeam dutyTeam)
    {
        List<DutyTeam> list = dutyTeamService.selectDutyTeamList(dutyTeam);
        ExcelUtil<DutyTeam> util = new ExcelUtil<DutyTeam>(DutyTeam.class);
        return util.exportExcel(list, "team");
    }

    /**
     * 新增轮值班组信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存轮值班组信息
     */
    @RequiresPermissions("duty:team:add")
    @Log(title = "轮值班组信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DutyTeam dutyTeam)
    {
        return toAjax(dutyTeamService.insertDutyTeam(dutyTeam));
    }

    /**
     * 修改轮值班组信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DutyTeam dutyTeam = dutyTeamService.selectDutyTeamById(id);
        mmap.put("dutyTeam", dutyTeam);
        return prefix + "/edit";
    }

    /**
     * 修改保存轮值班组信息
     */
    @RequiresPermissions("duty:team:edit")
    @Log(title = "轮值班组信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DutyTeam dutyTeam)
    {
        return toAjax(dutyTeamService.updateDutyTeam(dutyTeam));
    }

    /**
     * 删除轮值班组信息
     */
    @RequiresPermissions("duty:team:remove")
    @Log(title = "轮值班组信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dutyTeamService.deleteDutyTeamByIds(ids));
    }
}
